﻿using ConfExpert.Forms.Base;

using DevTeam;

using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class AksesuarRezerveSec : XForm
    {
        int brandId, sezonId;
        public AksesuarRezerveSec()
        {
            InitializeComponent();
        }

        public int AksesuarRezerveId
        {
            get { return RezerveId; }
        }

        public int BrandId
        {
            get
            {
                return brandId;
            }
        }
        public int SezonId
        {
            get { return sezonId; }
        }

        private void AksesuarIhtiyaci_Load(object sender, EventArgs e)
        {
            gvRezerve.Init("GetAksesuarRezerveByUser", WhoAmI, false);
            gvRezerve.AddDetailGrid(gvRezerveLines, "AksesuarRezerveId");

            gvRezerve.AddColumn("ToplamRezerve", typeof(int), "SUM(Child({FK}).RezerveMiktari)");

            gvRezerve.FormatAsNumber(0, "ToplamRezerve");
            gvRezerveLines.FormatAsNumber(0, "RezerveMiktari", "TalebeDonusen", "KalanRezerve");

            gvRezerveLines.AddSummary("RezerveMiktari");
            gvRezerve.AddSummary("ToplamRezerve");

            gvRezerveLines.MakeColumnInvisible("AksesuarRezerveId");

            GridManager gm = GridManager.GetManager(gvRezerve);
            gm.GridMenu.AddMenu("Ekle", RezerveyeEkle);

            BestFitColumnsForThisForm();
            splitContainerControl1.AutoSize();

        }

        int RezerveId;
        void RezerveyeEkle(object sender, EventArgs e)
        {
            DataRow dr = gvRezerve.GetDataRow(gvRezerve.FocusedRowHandle);
            int handle = gvRezerve.FocusedRowHandle;
            if (handle > -1)
            {
                int stGenelId = dr["stGenelId"].ToInt();
                if (stGenelId == 1)
                {
                    RezerveId = intParse(dr["AksesuarRezerveId"]);
                    brandId = dr["BrandId"].ToInt();
                    sezonId = dr["SezonId"].ToInt();
                    this.DialogResult = DialogResult.OK;
                }
            }
        }

        private void BestFitColumnsForThisForm()
        {
            gvRezerve.SetCaptions("AksesuarRezerveId:RzvNo");
            //gvRezerveLines.OptionsView.EnableAppearanceOddRow = false;
            //gvRezerveLines.OptionsView.EnableAppearanceEvenRow = false;  
            gvRezerve.BestFitColumns();
            gvRezerveLines.BestFitColumns();
            gvRezerve.Columns["Notlar"].Width = 100;
        }




    }
}